1. The sample driver uses 'allocb' to create a message block. After a period of time, allocb returns a NULL pointer. How should I handle this situation?
2. How and when is the receive block deallocated? Should my driver handle this,
or does something else in the stack handle it?
A 1. If you call allocb to create a message block and the call returns a null
pointer, your driver has hit a low memory situation, which means it's time to
start discarding packets.
2. The client should deallocate message blocks when finished. In the case you describe, they are not yet finished.
In terms of networking services, everyone, including OpenTransport, is a client to the driver. As packets come in, you need to use allocb or esballoc to create the message block to pass along to Open Transport. Once it is passed along, a client, most likely OpenTransport, processes the packet and releases (deallocates) the memory for that packet.
The 'esballoc' routine may be more suitable for your needs, since you can use it to allocate DMA memory and to pass along a notifier function that is called when the client is through using the memory. These are all standard STREAMS calls documented in Designing Cards and Drivers for PCI.
esballoc is used primarily to set up a message block for a buffer that is supplied by the driver (i.e., a DMA buffer). As part of the esballoc message, you pass a pointer to a free_rtn structure, which in turn points to a free routine.
On packet receipt, the driver needs to allocate a message block for use in
passing the packet data to it's clients. In this case, it is the clients
responsibility to call freemsg. To allocate a message block, there are two
options: allocb and esballoc. In one case, the memory for the data buffer comes
from the available system memory, while in the case of esballoc, memory is
allocated for the message block only. It is the responsibility of the driver to
provide the memory from DMA, e.g., for the data. As such, it is useful to
attach a free_rtn parameter so that when the data has been processed, the
driver will know memory is now available for use in processing another message.
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help